package com.example.chinawenddingexpo.repository;

import com.example.chinawenddingexpo.model.Event;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface EventRepository extends JpaRepository<Event, Long> {
    
    List<Event> findByStatusOrderByStartTimeAsc(Event.EventStatus status);
    
    List<Event> findByStartTimeAfterOrderByStartTimeAsc(LocalDateTime now);
    
    @Query("SELECT e FROM Event e WHERE e.startTime > :now AND e.currentParticipants < e.maxParticipants AND e.status = 'AVAILABLE' ORDER BY e.startTime ASC")
    List<Event> findAvailableEvents(@Param("now") LocalDateTime now);
    
    List<Event> findByEventTypeAndStatusOrderByStartTimeAsc(Event.EventType type, Event.EventStatus status);
}